home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 4 / FM Towns Free Software Collection 4 - Disc 1.iso / msdos / css / lib / glib.c next >
Encoding:
C/C++ Source or Header  |  1991-10-19  |  8.3 KB  |  343 lines

  1.  
  2. #include <stdio.h>
  3. #include <fmc.h>
  4.  
  5. /*
  6.     mode=0-3: テキスト・グラフィック画面消去
  7.     mode=4  : テキスト画面消去
  8.     mode=5  : グラフィック画面消去
  9. */
  10. void cls(int mode)
  11. {
  12.         if ((0 <= mode) && (mode <= 3)) printf("\x16");
  13.         if (mode == 4) printf("\x1b[2J");
  14.         if (mode == 5) printf("\x15");
  15. }
  16.  
  17. /*
  18.    cn: 桁数      ln:行数
  19. */
  20. void width(int cn, int ln)
  21. {
  22.         char *ps;
  23.  
  24.         if      ((cn == 40) && (ln == 25))  ps = "0";
  25.         else if ((cn == 40) && (ln == 20))  ps = "1";
  26.         else if ((cn == 80) && (ln == 25))  ps = "2";
  27.         else if ((cn == 80) && (ln == 20))  ps = "3";
  28.         else return;
  29.  
  30.         printf("\x1b[=%sh", ps);
  31. }
  32.  
  33. /*
  34.   x, y: 表示位置    sw: カーソルON,OFF  0=OFF,1=ON, 2=NOP
  35. */
  36. void locate(int x, int y, int sw)
  37. {
  38.         printf("\x1b=");
  39.         putchar(y+' ');
  40.         putchar(x+' ');
  41.  
  42.         if     (sw == 0) sw = 1;
  43.         else if(sw == 1) sw = 0;
  44.         else return;
  45.  
  46.         printf("\x1b[");
  47.         putchar(sw+'0');
  48.         printf("v");
  49. }
  50.  
  51. void cuon()
  52. {
  53.         printf("\x1b[0v");
  54. }
  55.  
  56. void cuoff()
  57. {
  58.         printf("\x1b[1v");
  59. }
  60.  
  61. /*
  62.     cl: カラー    bc: バックカラー
  63. */
  64. void color(int cl, int bc)
  65. {
  66.         if ((cl < 0) || (7< cl)) return;
  67.         if ((bc < 0) || (7< bc)) return;
  68.         
  69.         if      (cl == 1) cl = 4;
  70.         else if (cl == 2) cl = 1;
  71.         else if (cl == 3) cl = 5;
  72.         else if (cl == 4) cl = 2;
  73.         else if (cl == 5) cl = 6;
  74.         else if (cl == 6) cl = 3;
  75.  
  76.         if      (bc == 1) bc = 4;
  77.         else if (bc == 2) bc = 1;
  78.         else if (bc == 3) bc = 5;
  79.         else if (bc == 4) bc = 2;
  80.         else if (bc == 5) bc = 6;
  81.         else if (bc == 6) bc = 3;
  82.  
  83.         printf("\x1b[3");
  84.         putchar(cl+'0');
  85.         printf(";4");
  86.         putchar(bc+'0');
  87.         printf("m");
  88. }
  89.  
  90. void vattr(unsigned int attr)
  91. {
  92.    if (attr > 8) attr = 8;
  93.    printf("\x01b[");
  94.    putchar(attr+'0');
  95.    putchar('m');
  96. }
  97.  
  98.  
  99. GraphData GDS_data;
  100. /*
  101.     グラフィック処理 初期設定
  102. */
  103. void gopen()
  104. {       unsigned worksize=2048, size=500, pattern=0xffff;
  105.         char style=10;
  106.         unsigned char mode=1;
  107.         int ret;
  108.  
  109.         if ((GDS_open(worksize) < 0) || (GDS_initData(&GDS_data, size) < 0)) {
  110.                 printf("メモリー不足\n");
  111.         }
  112.         /* GDS_reset(); */
  113.         ret = GDS_linePattern(&GDS_data, style, pattern);
  114.         ret = GDS_lineStyle(&GDS_data, style);
  115.         ret = GDS_textMode(&GDS_data, mode); /* 文字 */
  116. }
  117.  
  118. /*
  119.     グラフィック処理 再度初期設定
  120. */
  121. void greset()
  122. {       unsigned size=500, pattern=0xffff;
  123.         char style=10;
  124.         unsigned char mode=1;
  125.         int ret;
  126.  
  127.         GDS_reset();
  128.         ret = GDS_linePattern(&GDS_data, style, pattern);
  129.         ret = GDS_lineStyle(&GDS_data, style);
  130.         ret = GDS_textMode(&GDS_data, mode); /* 文字 */
  131. }
  132.  
  133. /*
  134.     グラフィック処理 終了
  135. */
  136. void gclose()
  137. {
  138.         int ret;
  139.         
  140.         ret = GDS_close();
  141. }
  142.  
  143. /*
  144.    グラフィック出力
  145. */
  146. void gout()
  147. {
  148.     unsigned n, offset;
  149.     int ret;
  150.         ret = GDS_outputGraph(&GDS_data, &n, &offset);
  151.         ret = GDS_resetData(&GDS_data);
  152. }
  153.  
  154.  
  155. void drmode(unsigned mode)
  156. {       int ret;
  157.  
  158.         ret = GDS_drawMode(&GDS_data, mode);
  159. }
  160.  
  161.  
  162.  
  163. void pset(int x, int y, unsigned cl, unsigned mode)
  164. {
  165.         unsigned n, offset;
  166.         int ret;
  167.  
  168.         ret = GDS_pointColor(&GDS_data, cl);
  169.         ret = GDS_pointFirst(&GDS_data, x, y);
  170.  
  171.         ret = GDS_drawMode(&GDS_data, mode);
  172.         ret = GDS_outputGraph(&GDS_data, &n, &offset);
  173.         ret = GDS_resetData(&GDS_data);
  174. }
  175.  
  176. /* bf = 0:direct,  1:box,  2:box and paint, 3:box and tile, 4:box and hatch  */
  177. void line(int x1, int y1, int x2, int y2, unsigned mode, unsigned cl, unsigned bf, unsigned ls)
  178. {
  179.         char style=10;
  180.         unsigned int style2=0;
  181.         unsigned n, offset;
  182.         int ret;
  183.  
  184.         ret = GDS_drawMode(&GDS_data, mode);
  185.         ret = GDS_linePattern(&GDS_data, style, ls);
  186.         ret = GDS_lineColor(&GDS_data, cl);
  187.         
  188.         if (bf == 0) {
  189.                 ret = GDS_chainFirst(&GDS_data, x1, y1, x2, y2);
  190.         } else if (bf > 0) {
  191.                 style2=bf - 1;
  192.                 ret = GDS_fillStyle(&GDS_data, style2);
  193.                 ret = GDS_borderColor(&GDS_data, cl);
  194.                 ret = GDS_borderStyle(&GDS_data, style);
  195.                 ret = GDS_fillColor(&GDS_data, cl);
  196.                 ret = GDS_box(&GDS_data, x1, y1, x2, y2);
  197.         }
  198.  
  199.         ret = GDS_outputGraph(&GDS_data, &n, &offset);
  200.         ret = GDS_resetData(&GDS_data);
  201. }
  202.  
  203. /*
  204.      paint
  205.      x, y   : ペイント開始点
  206.      style  : 面塗りモード
  207.               0 : 塗らない
  208.               1 : 塗りつぶし
  209.               2 : タイル塗り
  210.               3 : ハッチング塗り
  211.                                    
  212.      pcl    : 面塗り(塗りつぶし/ハッチング)の色識別番号を指定します。
  213.      bcn    : 境界色数
  214.      *bcl   : 境界色を格納する配列
  215. */
  216. void paint(int x, int y, unsigned style, unsigned pcl, unsigned bcn, unsigned *bcl)
  217. {
  218.         unsigned n, offset;
  219.         int ret;
  220.  
  221.         if (style == 0) return;
  222.         ret = GDS_fillColor(&GDS_data, pcl);
  223.         ret = GDS_fillStyle(&GDS_data, style);
  224.         ret = GDS_paint(&GDS_data, x, y, bcn, bcl);
  225.  
  226.         ret = GDS_outputGraph(&GDS_data, &n, &offset);
  227.         ret = GDS_resetData(&GDS_data);
  228. }
  229.  
  230. void hatch(unsigned style)
  231. {
  232.         int ret;
  233.  
  234.         ret = GDS_hatchStyle(&GDS_data, style);
  235. }
  236.  
  237. void tile(unsigned style)
  238. {
  239.         int ret;
  240.  
  241.         ret = GDS_tileStyle(&GDS_data, style);
  242. }
  243.  
  244.  
  245. /*
  246.    symbol
  247.        x , y : 位置        *str : 文字列
  248.        wm    : 横倍率      hm   : 縦倍率   (8ドット)
  249.        cl    : パレットコード
  250.        ac    : 角度コード
  251.        mode  : 機能
  252. */
  253. void symbol(int x, int y, char *str, int wm, int hm, unsigned cl, unsigned ac, unsigned mode)
  254. {
  255.         int hx, hy, wx, wy, hi;
  256.         unsigned n, offset;
  257.         int ret;
  258.         
  259.         wm *= 2;
  260.         hi = hm * 8;
  261.         
  262.  
  263.         ret = GDS_drawMode(&GDS_data, mode);
  264.         ret = GDS_textColor(&GDS_data, cl);
  265.         ret = GDS_characterWidth(&GDS_data, wm, hm);
  266.         ret = GDS_characterHeight(&GDS_data, hi);
  267.         
  268.         if (ac == 0) {
  269.                 hx = 0; hy = -1;
  270.                 wx = 1; wy = 0;
  271.                 y += hi;
  272.         } else if (ac == 1) {
  273.                 hx = -1; hy = 0;
  274.                 wx =  0; wy = -1;
  275.                 x += hi;
  276.         } else if (ac == 2) {
  277.                 hx =  0; hy = 1;
  278.                 wx = -1; wy = 0;
  279.                 y -= hi;
  280.         } else if (ac == 3) {
  281.                 hx =  1; hy = 0;
  282.                 wx =  0; wy = 1;
  283.                 x -= hi;
  284.         } else return;
  285.         
  286.         ret = GDS_characterVector(&GDS_data, hx, hy, wx, wy);
  287.         ret = GDS_textPoint(&GDS_data, x, y);
  288.         ret = GDS_text(&GDS_data, str, strlen(str));
  289.  
  290.         ret = GDS_outputGraph(&GDS_data, &n, &offset);
  291.         ret = GDS_resetData(&GDS_data);
  292. }
  293.  
  294.  
  295. /*
  296.    symbol_
  297.        x , y : 位置        *str : 文字列
  298.        wm    : 横倍率      hm   : 縦倍率   (16ドット)
  299.        cl    : パレットコード
  300.        ac    : 角度コード
  301.        mode  : 機能
  302. */
  303. void symbol_(int x, int y, char *str, int wm, int hm, unsigned cl, unsigned ac, unsigned mode)
  304. {
  305.         int hx, hy, wx, wy, hi;
  306.         unsigned n, offset;
  307.         int ret;
  308.  
  309.         /* wm *= 2; */
  310.         hi = hm * 16;
  311.  
  312.         ret = GDS_drawMode(&GDS_data, mode);
  313.         ret = GDS_textColor(&GDS_data, cl);
  314.         ret = GDS_characterWidth(&GDS_data, wm, hm);
  315.         ret = GDS_characterHeight(&GDS_data, hi);
  316.  
  317.         if (ac == 0) {
  318.                 hx = 0; hy = -1;
  319.                 wx = 1; wy = 0;
  320.                 y += hi;
  321.         } else if (ac == 1) {
  322.                 hx = -1; hy = 0;
  323.                 wx =  0; wy = -1;
  324.                 x += hi;
  325.         } else if (ac == 2) {
  326.                 hx =  0; hy = 1;
  327.                 wx = -1; wy = 0;
  328.                 y -= hi;
  329.         } else if (ac == 3) {
  330.                 hx =  1; hy = 0;
  331.                 wx =  0; wy = 1;
  332.                 x -= hi;
  333.         } else return;
  334.  
  335.         ret = GDS_characterVector(&GDS_data, hx, hy, wx, wy);
  336.         ret = GDS_textPoint(&GDS_data, x, y);
  337.         ret = GDS_text(&GDS_data, str, strlen(str));
  338.  
  339.         ret = GDS_outputGraph(&GDS_data, &n, &offset);
  340.         ret = GDS_resetData(&GDS_data);
  341. }
  342.  
  343.